import 'package:hrf_app/common/index.dart';
import 'package:hrf_app/common/services/user.dart';
import 'package:hrf_app/common/widgets/navigation.dart';
import 'package:hrf_app/pages/main_tab/main_menu_tab/index.dart';
import 'package:hrf_app/pages/main_tab/main_my_tab/index.dart';
import 'package:hrf_app/pages/main_tab/main_tab/widgets/buttom_tabbar_data_handler.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

class MainTabController extends GetxController {
  MainTabController();

  final PageController pageController = PageController();
  int currentIndex = 0;
  List<NavigationItemModel> tabbarPermList = <NavigationItemModel>[];
  List<Widget> tabbarPermPageList = <Widget>[];

  // 切换页面
  void onJumpToPage(int page) {
    print(page);
    pageController.jumpToPage(page);
    currentIndex = page;
    update(['navigation']);
  }

  _initData() {
    _menuHasPermList();
    update(["mainTab"]);
  }

  void _menuHasPermList() {
    ButtonTabbarDataHandler menuDataHandler = ButtonTabbarDataHandler();
    List<NavigationItemModel> tabbarList = menuDataHandler.initializeMenuList();
    for (NavigationItemModel vo in tabbarList) {
      tabbarPermList.add(vo);
      tabbarPermPageList.add(vo.widget);
    }
  }

  @override
  void onInit() {
    super.onInit();
    _initData();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
    // 释放页控制器
    pageController.dispose();
  }
}
